
package ogame.utilities;

/**
 * This class implements a coordinate system utilized in ogame.
 * @author scchang
 */
public class Coords {
    protected int galaxy;
    protected int system;
    protected int planet;

    public Coords(int galaxy, int system, int planet) {
        this.galaxy = galaxy;
        this.system = system;
        this.planet = planet;
    }

    /**
     * @return the galaxy
     */
    public int getGalaxy() {
        return galaxy;
    }

    /**
     * @param galaxy the galaxy to set
     */
    public void setGalaxy(int galaxy) {
        this.galaxy = galaxy;
    }

    /**
     * @return the system
     */
    public int getSystem() {
        return system;
    }

    /**
     * @param system the system to set
     */
    public void setSystem(int system) {
        this.system = system;
    }

    /**
     * @return the planet
     */
    public int getPlanet() {
        return planet;
    }

    /**
     * @param planet the planet to set
     */
    public void setPlanet(int planet) {
        this.planet = planet;
    }
    
    public static double getDistance(Coords one, Coords two){
        // Couple different cases
        if(one.getGalaxy() != two.getGalaxy()){
            return 20000 * Math.abs(one.getGalaxy() - two.getGalaxy());
        }else if(one.getSystem() != two.getSystem()){
            return 2700 + 95 * Math.abs(one.getSystem() - two.getSystem());
        }else if(one.getPlanet() != two.getPlanet()){
            return 1000 + 5 * Math.abs(one.getPlanet() - two.getPlanet());            
        }else{
            return 5;
        }
    }
    /**
     * 
     * @param one
     * @param two
     * @return Duration in seconds
     */
    public static double getDuration(Coords one, Coords two, double speed, double percent){
        return 10.0 + 3500/percent*Math.sqrt((10.0*getDistance(one, two))/speed);
    }
    
    public String toString(){
        return "[" + this.galaxy + ":" + this.system + ":" + this.planet + "]";
    }

    public boolean equals(Object in){
        if(!(in instanceof Coords)){
            return false;
        }
        Coords in_coords = (Coords)in;
        if((in_coords.getGalaxy() != this.getGalaxy()) ||
                (in_coords.getSystem() != this.getSystem()) ||
                (in_coords.getPlanet() != this.getPlanet())){
            return false;
        }
        return true;
    }
    
}
